<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>提现管理</title>
    <link rel="stylesheet" type="text/css" href="static/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="static/admin/css/admin.css"/>
</head>
<body>
<div class="wrap-container welcome-container">
    <div class="wrap-container clearfix">
        <div class="column-content-detail">
            <div class="layui-form-item">
                <div class="layui-inline" style="margin-bottom: 0;">
                    <input type="text" name="accountdata" required lay-verify="required" placeholder="请输入账号" autocomplete="off" class="keywords layui-input">
                </div>
                <button class="layui-btn layui-btn-normal search">搜索</button>
            </div>
            <div class="layui-form" id="table-list">
                <table class="layui-table" lay-even lay-skin="nob">
                    <thead>
                    <tr>
                        <th>真实姓名</th>
                        <th>提现金额(元)</th>
                        <th>提现方式</th>
                        <th>提现账号</th>
                        <th>到账金额(元)</th>
                        <th>服务费(元)</th>
                        <th>状态</th>
                        <th>提现时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody class="table-content"></tbody>
                </table>
                <div class="page-wrap">
                    <div id="page"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="user-edit-popup">
    <form class="layui-form" id="form">
        <input type="hidden" name="id" id="user-id">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="name" data-name="用户名" required lay-verify="required" placeholder="请输入用户名"
                       autocomplete="off" class="required layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上级</label>
            <div class="layui-input-inline">
                <input type="text" name="superior" data-name="上级" required lay-verify="required" placeholder="请输入上级"
                       autocomplete="off" class="layui-input required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">级别</label>
            <div class="layui-input-inline">
                <input type="text" name="level" data-name="级别" required lay-verify="required" placeholder="请输入级别"
                       autocomplete="off" class="layui-input required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">VIP</label>
            <div class="layui-input-inline">
                <div class="layui-form-item">
                    <select id="isVIP" name="isVIP" lay-verify="">
                        <option value="">是否是VIP</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="static/admin/js/baseUrl.js"></script>
<script type="text/javascript">
    layui.use(['layer', 'jquery', 'laypage'], function () {
        var layer = layui.layer;
        var $ = layui.jquery;
        var laypage = layui.laypage;
        // 请求参数
        var requestData = {
            currentNum: 1,
            currentSize: 10
        };
        // 提现方式
        var payStatusText = ['','支付宝','微信','银行卡']
        // 获取数据
        function getList(params) {
            $.ajax({
                url: baseUrl + '/deposit/selectAllDeposit',
                data: params,
                type: 'get',
                dataType: 'json',
                contentType: 'application/json',
                withCredentials: true,
                xhrFields: {
                    withCredentials: true
                },
                success: function (data) {
                    console.log(data);
                    if(data.ret == 200) {
                        var list = data.data.list;
                        if(list.length > 0) {
                            var html = '';
                            for(var item of list) {
                                html += `<tr>
                                <td class="">${item.realName}</td>
                                <td class="">${item.money}</td>
                                <td class="">${payStatusText[item.payStatus]}</td>
                                <td>${(item.payStatus==3 ? item.realName + '-' : '')} ${item.account}</td>
                                <td>${item.status == 2 ?(item.money - 3) : 0}</td>
                                <td>3</td>
                                <td class="">${item.status == 1 ? '提现申请中' : '提现成功'}</td>
                                <td class="">${item.createTima}</td>
                                <td>
                                    <div class="layui-inline">
                                        <button class="layui-btn layui-btn-sm layui-btn-normal finish-withdrawal ${item.status==2 && 'layui-btn-disabled'}" data-name="${item.realName}" data-money="${item.money}" data-account="${item.account}" data-paystatus="${item.payStatus}" data-id="${item.id}" data-status="${item.status}">${item.status==2?'审核成功':'待审核'}</button>
                                    </div>
                                </td>
                            </tr>`
                            }
                            $('.table-content').html(html);
                            laypage.render({
                                elem: 'page',
                                count: data.data.total,
                                curr: requestData.currentNum,
                                jump: function(obj, first) {
                                    if (!first) {
                                        requestData.currentNum = obj.curr;
                                        getList(requestData)
                                    }
                                }
                            });
                        }else {
                            layer.msg('暂无数据')
                        }
                    }else {
                        if (data.ret == 208) {
                            parent.layer.alert(data.msg, {icon: 0}, function () {
                                parent.location.href = 'login.html'
                            })
                        } else {
                            layer.msg(data.msg, {icon: 0, time: 1000});
                        }
                    }
                },
                error: function () {
                    layer.msg('网络发生故障，请稍后再试', {icon: 0, time: 1000});
                }
            })
        }
        // 初始数据请求
        getList(requestData);

        $('.search').click(function () {
            data.phone = $('.keywords').val();
            data.page = 1;
            //发起请求
            getList(data);
        });

        // 审核提现
        $('.layui-table').on('click', '.finish-withdrawal', function () {
            var $tar = $(this);
            $tar.data('status') == 1 && layer.confirm('确定通过此条提现记录吗？', {icon: 0},function (index) {
                var loading = layer.load(1, {shade: [0.3, '#000']});
                layer.close(index);
                // 发起审核通过请求
                $.ajax({
                    url: baseUrl + '/deposit/insertDeposit',
                    data: JSON.stringify({
                        id: $tar.data('id'),
                        realName: $tar.data('name'),
                        money: $tar.data('money'),
                        account: $tar.data('account'),
                        payStatus: $tar.data('paystatus')
                    }),
                    type: 'post',
                    dataType: 'json',
                    contentType: 'application/json',
                    withCredentials: true,
                    xhrFields: {
                        withCredentials: true
                    },
                    success: function (data) {
                        // console.log(data);
                        layer.msg(data.msg, {icon: data.ret == 200 ? 1 : 0},function () {
                            data.ret == 200 && location.reload();
                        })
                    },
                    error: function () {
                        layer.msg('网络发生故障，请稍后再试', {icon: 0, time: 1000});
                    },
                    complete: function () {
                        layer.close(loading);
                    }
                })
            })
        })
    })
</script>
</body>
</html>
